<div class="row deploy-check">
  <% if status = CommitStatus.new(@deploy.stage, @deploy.reference) rescue nil %>
    <p>
      Commit status for <%= short_sha @deploy.reference %>: <%= status.status %><br/>
      <% status.status_list.each do |info| %>
        <%= info.fetch(:state) %>: <%= info.fetch(:description) %><br/>
      <% end %>
    </p>
  <% else %>
    <p>Error fetching commit status.</p>
  <% end %>
  <br/><br/>

  <% if @deploy.started_by?(current_user) %>
    <p>This deploy requires a buddy since it is going to production. Please have another engineer with deploy rights visit this URL to kick off the deploy.</p>
    <% if details = ENV["BYPASS_DETAILS"].presence %>
      <p><%= details.html_safe %></p>
    <% end %>

    <div>
      <%= cancel_button deploy: @deploy, project: @project %>
      or
      <% confirm = "Are you sure this is an emergency and you cannot find a buddy?\n#{strip_tags(details)}" %>
      <%= link_to "Bypass", buddy_check_project_deploy_path(@project, @deploy), method: :post, data: {confirm: confirm}, class: "btn btn-danger" %>
    </div>
  <% elsif deployer_for_project? %>
    <p>This deploy requires a buddy.</p>
    <div class="buddy-approval">
      <%= link_to "Approve", buddy_check_project_deploy_path(@project, @deploy), method: :post, class: "btn btn-primary btn-xl" %>
      <% if @deploy.can_be_cancelled_by?(current_user) %>
        or
        <%= cancel_button deploy: @deploy, project: @project %>
      <% end %>
    </div>
  <% else %>
    <p>This deploy requires a buddy since it is going to production. (Someone with deploy rights or greater.)</p>
  <% end %>
</div>
